import * as actionTypes from './actionTypes'
import axios from 'axios'
import { fromJS } from 'immutable'
const ActionGetHomeData = (data) => ({
    type: actionTypes.GET_HOME_DATA,
    articleList: data.articleList,
    recommendList: data.recommendList,
    topicList: data.topicList
})

const ActionGetMoreList = (data,page) => ({
    type: actionTypes.GET_MORE_DATA,
    list: fromJS(data),
    page: fromJS(page),
})

export const getHomeData = () => {
    return (dispatch, getState) => {
        
        axios.get('/api/home.json').then((res) => {
            dispatch(ActionGetHomeData(res.data.data))
        })
        const state = getState();
        // const dataFromB = selectImportantDataFromB(state);
        // dispatch({
        //     type : "123",
        //     payload : {
        //         dataFromB
        //     }
        // });
        console.log(state)
    }
}

export const getMoreList = (page) =>{
    return (dispatch) => {
        axios.get('/api/homeList.json?page='+page).then((res) => {
            dispatch(ActionGetMoreList(res.data.data, page+1)) 
        })
    }
}
